package com.eonmind.ai.mapper;

import com.eonmind.common.contract.data.base.BaseMongoMapper;
import com.eonmind.common.contract.data.request.PageRequest;
import com.eonmind.common.contract.enums.DelEnum;
import com.eonmind.common.contract.enums.ai.AiVideoStatusEnum;
import com.eonmind.common.provider.entity.ai.AiVideo;
import com.mongoplus.conditions.query.QueryWrapper;
import com.mongoplus.model.PageResult;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AiVideoMapper extends BaseMongoMapper<AiVideo> {


    public AiVideo selectById(Long id) {
        QueryWrapper<AiVideo> eq = createMgoQuery()
                .eq(AiVideo::getId, id)
                .eq(AiVideo::getDel, DelEnum.UN_DEL.getCode());
        return one(eq);
    }

    public List<AiVideo> selectByStatus(Integer code) {
        QueryWrapper<AiVideo> eq = createMgoQuery()
                .eq(AiVideo::getStatus, code)
                .eq(AiVideo::getDel, DelEnum.UN_DEL.getCode());
        return list(eq);
    }

    public List<AiVideo> selectAllSyncData() {
        QueryWrapper<AiVideo> mgoQuery = createMgoQuery().or(t -> {
            return t.eq(AiVideo::getStatus, AiVideoStatusEnum.PENDING_GENERATION.getCode())
                    .eq(AiVideo::getStatus, AiVideoStatusEnum.GENERATING.getCode());
        });

        mgoQuery.eq(AiVideo::getDel, DelEnum.UN_DEL.getCode());
        return list(mgoQuery);
    }

    public PageResult<AiVideo> pageVideo(PageRequest page, Long id) {

        QueryWrapper<AiVideo> eq = createMgoQuery()
                .eq(AiVideo::getUserId, id)
                .eq(AiVideo::getDel, DelEnum.UN_DEL.getCode());
        return page(eq, page);
    }
}
